package cn.kai.basic.controller;

import cn.kai.basic.service.IVerifyCodeService;
import cn.kai.basic.util.AjaxResult;
import cn.kai.basic.vo.RegisterVo;
import cn.kai.basic.vo.RegisterVoEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.security.Key;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    @GetMapping("image/{key}")
    public AjaxResult graph(@PathVariable("key") String uuid){
        String base64Code =  verifyCodeService.graph(uuid);
        return AjaxResult.me().success(base64Code);
    }

    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid RegisterVo vo){
        verifyCodeService.smsCode(vo);
        return AjaxResult.me().success();
    }

    @PostMapping("/smsCodeEmail")
    public AjaxResult smsCodeEmail(@RequestBody @Valid RegisterVoEmail vo){
        verifyCodeService.smsCodeEmail(vo);
        return AjaxResult.me().success();
    }
}
